﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Renci.SshNet;
using System.IO;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace SSHTool.RRU_QUERY
{

    public partial class LinuxCmdDemo : Form
    {
        public LinuxCmdDemo()
        {
            InitializeComponent();
        }
        Renci.SshNet.SshClient sshC = null;

        private void btn_C1_Click(object sender, EventArgs e)
        {
         sshC = new SshClient(txt_ip1.Text,txt_user1.Text,txt_pwd1.Text);

         sshC.Connect();


         if (sshC.IsConnected)
         {
             lab_ContentState1.Text = "连接状态：成功";
         }
         else
         {
             lab_ContentState1.Text = "连接状态：失败";
         }

        }

        private void btn_Q1_Click(object sender, EventArgs e)
        {
            Renci.SshNet.SshClient _session = new Renci.SshNet.SshClient(txt_ip1.Text,txt_user1.Text,txt_pwd1.Text);

            SshCommand x = sshC.RunCommand(txt_cmd1.Text);
            //SshCommand z2 = sshC.RunCommand(txt_cmd1.Text);
            //string z1 = z2.Execute(txt_cmd1.Text);

            txt_Show1.Text = "结果信息\n"+ x.Result+"错误信息:"+x.Error;

           // txt_Show1.Text += "错误信息\n" + x.Error;
            //txt_Show1.Text += z1;

        }

        private void btn_C2_Click(object sender, EventArgs e)
        {
              
            /*
             * Resources.HOST 192.168.10.131
             * Resources.PORT 22
             * Resources.USERNAME root
             * proxyHost 
             * Resources.PORT
             * Resources.USERNAME
             * Resources.PASSWORD
             * Resources.USERNAME
             */
            var connectionInfo = new ConnectionInfo("10.69.66.67", 22, "toor4nsn",
                ProxyTypes.None, "192.168.253.18", 22, "toor4nsn", "oZPS0POrRieRtu",
                new KeyboardInteractiveAuthenticationMethod("10.69.66.67"));

            //var connectionInfo2 = new ConnectionInfo("192.168.253.18", 22, "toor4nsn",
            //    ProxyTypes.None, "10.69.66.67", 22, "toor4nsn", "oZPS0POrRieRtu",
            //    new KeyboardInteractiveAuthenticationMethod("192.168.253.18"));

             Renci.SshNet.SshClient _session2 = new Renci.SshNet.SshClient(connectionInfo);
             _session2.Connect();
             _session2.RunCommand("lst");

            //Renci.SshNet.Session zz = new Renci.SshNet.Session(,);
            //xx.Start();

        }

        private void btn_Q2_Click(object sender, EventArgs e)
        {

        }

        private void btn_C3_Click(object sender, EventArgs e)
        {

        }

        private void btn_Q3_Click(object sender, EventArgs e)
        {

        }

        private void T_1_Click(object sender, EventArgs e)
        {
            Renci.SshNet.SftpClient sftp1 = new SftpClient(txt_ip4.Text,txt_user4.Text,txt_pwd4.Text);
            sftp1.Connect();

            byte[] bytes= {12,2,3,4,};
            Stream stream = new MemoryStream(bytes);
            sftp1.UploadFile(stream, "/home/administrator/Documents/yhq.tar",null);


        }



      
    }
}
